package data.repository;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import data.entities.*;

public class HibernateUtil {
	private static final SessionFactory sessionFactory;
	
	static {
		try {
			AnnotationConfiguration config = new AnnotationConfiguration();
			
			config.addAnnotatedClass(Usuario.class);
			config.addAnnotatedClass(TipoPago.class);
			config.addAnnotatedClass(Cancha.class);
			config.addAnnotatedClass(Cliente.class);
			config.addAnnotatedClass(Socio.class);
			config.addAnnotatedClass(CalendarioClase.class);
			config.addAnnotatedClass(Clase.class);
			config.addAnnotatedClass(Ficha.class);
			config.addAnnotatedClass(Cuota.class);
			config.addAnnotatedClass(CalendarioReserva.class);
			config.addAnnotatedClass(ReservaCancha.class);
			config.addAnnotatedClass(PagoCancha.class);
			
			sessionFactory = config.buildSessionFactory();
		} catch (Throwable ex) {
			System.err.println("Initial SessionFactory creation failed." + ex);
			
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
}
